<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="__PUBLIC__/X-admin/css/x-admin.css" media="all">
</head>
<body>
        <div class="x-body">
            <form class="layui-form layui-form-pane" action="" method="post">

              <!-- 隐藏id 判断开关按钮-->
              <input type="hidden" id="sid" value="0">
              <input type="hidden" id="oid" value="{$list['id']}">
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        发送人
                    </label>
                    <div class="layui-input-block">
                       <input type="text" name="addresser" id="addresser" value="{$list['addresser']}" required disabled lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                       标题
                    </label>
                    <div class="layui-input-block">
                       <input type="text" name="title" id="title" required value="{$list['title']}" lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <br>

                <div class="layui-form-item layui-form-text">
                    <div class="layui-input-block">
                        <textarea name="contents" id="contents" style="display: none;">{$list['contents']}</textarea>
                    </div>
                      <label for="L_content" class="layui-form-label" style="top: -2px;">
                          描述
                      </label>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        草稿：<input type="checkbox" name="anonymity" id="anonymity"  lay-skin="switch" lay-text="草稿|发送" lay-filter="anonymity">
                        <span class="x-red">&nbsp;&nbsp;&nbsp;&nbsp;*</span><span style="color:#696969;">如果开启,则存为草稿</span>
                        <button class="layui-btn" lay-submit lay-filter="add" style="float: right; margin-right:50px">发布</button>
                    </div>
                       
                </div>
            </form>
        </div>
  </body>
</html>
  
   <script src="__PUBLIC__/X-admin/lib/layui/layui.js" charset="utf-8"></script>
   <script src="__PUBLIC__/X-admin/js/x-layui.js" charset="utf-8"></script>
   <script>
        layui.use(['form','layer'], function(){
              $ = layui.jquery;
              var form = layui.form();
              layer = layui.layer;

              //建立编辑器
              layui.use('layedit', function(){
                   layedit = layui.layedit;
                   indexedit = layedit.build('contents',{
                    hideTool: ['image']
                  }); 
                  // layedit.sync(indexedit);
                });
             

              // 监听匿名开关
              form.on('switch(anonymity)', function(data){
                // alert("asd")
                  //开关是否开启，true或者false
                  if (data.elem.checked) {
                     id=$("#sid").val(1);
                  }else{
                     id=$("#sid").val(0);
                  }
               }); 
              //监听提交
              form.on('submit(add)', function(data){
                id=$("#sid").val();
                oid=$("#oid").val();
                // alert(id);
                addresser=$("#addresser").val();
                title=$("#title").val();
                contents = document.getElementById('contents').value=layedit.getContent(indexedit);
                $.post('__URL__/updates',{id:id,oid:oid,title:title,addresser:addresser,contents:contents},function(data){                  
                    if(data==1){
                       layer.alert("成功", {icon: 6},function () {
                          // 获得frame索引
                          var index = parent.layer.getFrameIndex(window.name);
                          //关闭当前frame
                          parent.layer.close(index);
                          parent.reload();
                       });
                    }else{
                       layer.alert("失败", {icon: 6,time:2000},function () {
                            return false;
                       });
                    }
                });
                return false;
             });
          }); 
         
    </script>
